// pages/my/saleData/saleDataDetail.js
const app = getApp()
Page({
  data: {
    start:'',
    end:'',
    list:[],
    month:'',
    price:''
  },
  onLoad: function (options) {
    let [type,start,end,isOldForNew,price,title] = [options.id,options.start,options.end,0,options.price,'']
    //1.正常销售营业额（元）2.正常销售利润（元）3.以旧换新营业额（元）4.以旧换新利润（元）
    let month = start.split('-')[0]+'-'+start.split('-')[1]
    
    console.log(type)
    switch (type)
    {
      case '1':
      wx.setNavigationBarTitle({
        title: '正常销售营业明细'
      })
      title = '正常销售营业（元）'
      isOldForNew = 0
      break;
      case '2':
      wx.setNavigationBarTitle({
        title: '正常销售利润明细'
      })
      title = '正常销售利润（元）'
      isOldForNew = 0
      break;
      case '3':
      wx.setNavigationBarTitle({
        title: '以旧换新营业明细'
      })
      title = '以旧换新营业（元）'
      isOldForNew = 1
      break;
      case '4':
      wx.setNavigationBarTitle({
        title: '以旧换新利润明细'
      })
      title = '以旧换新利润（元）'
      isOldForNew = 1
      break;
    }
    this.setData({
      start,end,type,month,price,title
    })
    app.getMemInfo().then(res=>{
      this.getDetailList(res.data.id,isOldForNew)
    })
  },
  getDetailList(accountId,isOldForNew){
    let data = {
      accountId,
      startTime:this.data.start,
      endTime:this.data.end,
      isOldForNew,
      pageNum:1,
      pageSize:10
    }
    console.log(data)
    app.request('wx_app/agent/cashier/list',data,'GET').then(res=>{
      console.log(res)
      if (res.code==1) {
        let list = []
        res.data.forEach(item=>{
          list.push({
            payWay:item.payWay==1?'线下支付':'微信支付',
            turnover:item.zonge>0?'+'+item.zonge:item.zonge,
            profit:item.lirun>0?'+'+item.lirun:item.lirun,
            time:item.time,
            name:item.accountName,
            role:item.role,
            orderId:item.orderId
          })
        })
        this.setData({
          list
        })
      }else{
        app.errorMsg(res.message)
      }
    })
  },
  bindOrderDetail(e){
    let id = e.currentTarget.dataset.id
    console.log(id)
    if (this.data.type==1||this.data.type==2) {
      wx.navigateTo({
        url:'../orderDetail/orderDetail?orderId='+id+'&type=0&pay=1'
      })
    }else{
      wx.navigateTo({
        url:'../replaceProduct/replacePay?orderId='+id+'&type=2'
      })
    }
  }
})